package com.gba.mark.group.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.gba.mark.group.entity.Group;
import com.gba.mark.group.mapper.GroupMapper;
import com.gba.mark.group.service.IGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements IGroupService {

    @Autowired
    private IGroupService groupService;

    @Override
    public boolean saveGroup(String language, String name, Integer size, Integer admin_id) {
        Group group = new Group();
        // 判断组名是否重复
        if (this.baseMapper.selectOne(new QueryWrapper<Group>()
                .eq("admin_id", admin_id)
                .eq("name", group.getName())) != null) {
            return false;
        }
        // 存入数据：小组名称、人数、语种、管理员
        group.setName(name);
        group.setSize(size);
        group.setLanguage(language);
        group.setAdmin_id(admin_id);
        return groupService.save(group);
    }

    @Override
    public boolean removeGroup(String group_name, int admin_id) {
        return groupService.remove(new QueryWrapper<Group>()
                .eq("admin_id", admin_id)
                .eq("name", group_name));
    }



    //查找组信息
    @Override
    public List<Group> searchGroup(int admin_id) {
        return this.baseMapper.selectList(new QueryWrapper<Group>().eq("admin_id", admin_id));
    }

}
